package gentle.service.impl;


import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.SqlMapper;
import gentle.base.StringUtil;
import gentle.entity.RootImageInfo;
import gentle.entity.SearchRootImageInfo;
import gentle.mapper.DentalImageDao;
import gentle.service.IDentalImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 质量管理Dao
 */
@Service
public class DentalImageServiceImpl implements IDentalImageService {
    @Autowired
    private DentalImageDao dao;

    @Autowired
    private SqlMapper sqlMapper;

    public List<RootImageInfo> selectPageListByOrthodontics(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getType())) {
            params.put("type", searchInfo.getType());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCorea())) {
            if ("1".equals(searchInfo.getCorea())) {
                params.put("corea", "( " + " SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)>=(SELECT score from inco_info_orthodontics limit 1 )");
            } else {
                params.put("corea", "( " + " SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)<(SELECT score from inco_info_orthodontics limit 1 )");
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesOrthodontics(page, params);
    }

    public int getOrthodonticsPageCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getType())) {
            params.put("type", searchInfo.getType());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        if (StringUtil.isNotEmpty(searchInfo.getHeeStatus())) {
            params.put("heeStatus", searchInfo.getHeeStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCorea())) {
            if ("1".equals(searchInfo.getCorea())) {
                params.put("corea", "( " + " SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)>=(SELECT score from inco_info_orthodontics limit 1 )");
            } else {
                params.put("corea", "( " + " SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)<(SELECT score from inco_info_orthodontics limit 1 )");
            }
        }
        return dao.getQueryPagesOrthodonticsCount(page, params);
    }

    public List<RootImageInfo> selectPageListByCanal(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        } else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesCanal(page, params);
    }
    public int getQueryPageCanalCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        return dao.getQueryPagesCanalCount(page, params);
    }

    public List<RootImageInfo> selectPageListByScaling(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesScaling(page, params);
    }

    public int getQueryPageScalingCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        return dao.getQueryPagesScalingCount(page, params);
    }

    public List<RootImageInfo> selectPageListByRepair(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesRepair(page, params);
    }

    @Override
    public int getQueryPageRepairCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        return dao.getQueryPagesRepairCount(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByPeriodontal(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesPeriodontal(page, params);
    }

    @Override
    public int getQueryPagePeriodontalCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        return dao.getQueryPagesPeriodontalCount(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByPlant(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesPlant(page, params);
    }

    @Override
    public int getQueryPagePlantCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            if ("1".equals(searchInfo.getRoleId()) || "1,".equals(searchInfo.getRoleId().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", searchInfo.getUserAccount());
            }
        }
        return dao.getQueryPagesPlantCount(page, params);
    }

    @Override
    public List<RootImageInfo> getImgcancel(String num, String iconType, String classification) {
        String sql = "select * from root_orthodontics_imgs_info where num='" + num + "' and imgtpye='" + iconType + "' and classification='" + classification + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        return infoList;
    }

    @Override
    public List<RootImageInfo> getImgcancel(String num) {
        String sql = "select * from root_canal_imgs_info where num='" + num + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        return infoList;
    }

    public List<RootImageInfo> getScalingImgcancel(String num, String iconType, String classification) {
        String sql = "select * from root_scaling_imgs_info where num='" + num + "' and imgtpye='"+iconType+"' and classification='"+classification+"'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        return infoList;
    }

    public List<RootImageInfo> getPerioImgcancel(String num, String iconType, String classification) {
        String sql = "select * from root_periodontal_imgs_info where num='" + num + "' and imgtpye='"+iconType+"' and classification='"+classification+"' ";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        return infoList;
    }

    @Override
    public List<RootImageInfo> getPlantImgcancel(String num) {
        String sql = "select * from root_plant_imgs_info where num='" + num + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        return infoList;
    }

    @Override
    public List<RootImageInfo> getRepairImgcancel(String num, String iconType, String classification) {
        String sql = "select * from root_repair_imgs_info where num='" + num + "' and imgtpye='"+iconType+"' and classification='"+classification+"'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        return infoList;
    }


}
